package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @Author zhmwi
 * @Date 2021/9/4
 * @Dersciption
 */
@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierDao supplierDao;
    //分页查询供应商
    @Override
    public PageInfo<Supplier> getSupplierList(Integer page, Integer rows, String supplierName) {
        PageHelper.startPage(page,rows);
        List<Supplier> supplierList = supplierDao.selectSupplierList(supplierName);
        PageInfo<Supplier> pageInfo = new PageInfo<>(supplierList);
        return pageInfo;
    }

    //新增供应商
    @Override
    public boolean save(Supplier supplier) {
        return supplierDao.saveSupplier(supplier);
    }

    //批量删除供应商
    @Override
    public boolean delete(String ids) {
        if (StringUtils.isEmpty(ids)){
            return false;
        }
        String[] split = ids.split(",");
        for (String id : split) {
            supplierDao.delete(id);
        }
        return true;
    }

    //更新供应商
    @Override
    public Boolean update(Supplier supplier) {
        return supplierDao.update(supplier);
    }

    //模糊查询供应商名称
    @Override
    public List<Supplier> getComboboxList(String q) {
        return supplierDao.selectComboboxList(q);
    }
}
